﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using Banking.Khach_hang;
using Banking.Nhân_viên;
using Banking.Member;
using Banking.Quản_lý;
using DTO;
using DAO;
namespace Banking
{
    public partial class fmrMain : Office2007Form
    {
        /// <Thien>
        ///
        public TypeDemo type = new TypeDemo();
        Quản_lý.InsertChucVu themChucVu;
        Quản_lý.DanhSachChucVu dsChucVu;
        Quản_lý.XemDanhSachChucVuDaXoa dsChucVuDaXoa;
        Quản_lý.ThemNhanVien themNhanVien;
        DanhSachNhanVien dsNV;
        DanhSachKhachHang dsKH;
        DangKyKhachHangCaNhan uCtrDKCN;
        DangKyKhachHangDoanhNghiep uCtrDKDN;
        /// </Thien>
        ThongTinCaNhan_NhanVien thongTinKhachHang;
        private KhachHang _khachHang = new KhachHang();
        private KhachHangDA _khachHangDA = new KhachHangDA();
        private TaiKhoanChinh _taiKhoanChinh = new TaiKhoanChinh();
        private TaiKhoanDangNhap _taiKhoanDangNhap = new TaiKhoanDangNhap();
        ThongTinTaiKhoanCaNhan thongTinTKThe;
        /// <trinh>
        DichVuNganHang uCtrDVNganHang;
        LaiSuatNganHang uCtrLaiSuat;
        ATM uCtrATM;
        TyGia uCtrTyGia;
        /// </trinh>
        private TaiKhoanDangNhapNV taiKhoanDangNhapNV = new TaiKhoanDangNhapNV();
        ThongTinCaNhan thongTinCaNhan;
        /// <summary>
        /// /
        /// </summary>
        private TaiKhoanVayCtrl taiKhoanVay;
        ThongTinTaiKhoanTietKiem taiKhoanTietKiem;
        LichSuTruyCapctrl lichSuTruyCap;

        public int GetTypeDemo()
        {
            type.typeDemo = -1;
            type.typeDemo = cmbType.SelectedIndex;
            type.typeDemo += 1;
            return type.typeDemo;
        }

        public fmrMain()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            _taiKhoanDangNhap = TaiKhoanDangNhapDA.GetByID(1);
            _taiKhoanChinh = TaiKhoanChinhDA.GetByID(1);

            taiKhoanDangNhapNV = TaiKhoanDangNhapNVDAO.GetByID(1);
            cmbType.SelectedIndex = 0;
        }

        private void ribbonBar1_ItemClick(object sender, EventArgs e)
        {

        }

        private void btnKhuyenMai_Click(object sender, EventArgs e)
        {

        }

        private void buttonItem17_Click(object sender, EventArgs e)
        {

        }

        private void navigationPane1_Load(object sender, EventArgs e)
        {

        }

        private void buttonItem14_Click(object sender, EventArgs e)
        {

        }

        private void btnCustomer_Click(object sender, EventArgs e)
        {

        }

        private void buttonItem2_Click(object sender, EventArgs e)
        {

        }

        private void btnStaff_Click(object sender, EventArgs e)
        {

        }

        private void buttonItem14_Click_1(object sender, EventArgs e)
        {

        }

        private void itemPanel2_ItemClick(object sender, EventArgs e)
        {

        }

        private void btnXemDS_Click(object sender, EventArgs e)
        {
            dsKH = new DanhSachKhachHang(type);
            panelEx2.Controls.Clear();
            panelEx2.Controls.Add(dsKH);
        }

        private void btnXemTT_Click(object sender, EventArgs e)
        {
            panelEx2.Controls.Clear();
            thongTinKhachHang = new ThongTinCaNhan_NhanVien();
            thongTinKhachHang.init(_taiKhoanChinh.MaKH);
            panelEx2.Controls.Add(thongTinKhachHang);

        }

        private void btnDNhap_Click(object sender, EventArgs e)
        {
            //frmDangNhap f = new frmDangNhap();
            //f.ShowDialog();
            //try
            //{
            //    _taiKhoanChinh = f.TaiKhoanDangNhap.TaiKhoanChinh;
            //    _taiKhoanDangNhap = f.TaiKhoanDangNhap;

            //}
            //catch
            //{
            //    MessageBox.Show("bạn chưa đăng nhập", "BankingSystem", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            //}
            frmDangNhap f = new frmDangNhap();
            f.ShowDialog();
            try
            {
                taiKhoanDangNhapNV = f.TaiKhoanDangNhap;

            }
            catch
            {
                MessageBox.Show("bạn chưa đăng nhập", "BankingSystem", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            
        }

        private void btnDangXuat_Click(object sender, EventArgs e)
        {
            frmThayDoiMatKhau f = new frmThayDoiMatKhau();
            f.init(_taiKhoanDangNhap);
            f.ShowDialog();
        }

        private void btnLichSu_Click(object sender, EventArgs e)
        {
            panelEx2.Controls.Clear();
           lichSuTruyCap = new LichSuTruyCapctrl();
           lichSuTruyCap.LoadLichSuTruyCap(_taiKhoanDangNhap.MaTK);
           panelEx2.Controls.Add(lichSuTruyCap);

        }

        private void btnLickTruyCapGanNhat_Click(object sender, EventArgs e)
        {
            lichSuTruyCap = new LichSuTruyCapctrl();
            LichSuTruyCap lstc = new LichSuTruyCap();
            lstc = lichSuTruyCap.LoadLichSuTruyCapGanNhat(_taiKhoanDangNhap.MaTK);
            MessageBox.Show(lstc.NgayTruyCap.ToString(), "Ngày truy cập gần nhất", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void btnTaiKhoanThe_Click(object sender, EventArgs e)
        {
            panelEx2.Controls.Clear();
            thongTinTKThe = new ThongTinTaiKhoanCaNhan();
            thongTinTKThe.Load(_taiKhoanDangNhap.MaTK,type);
            panelEx2.Controls.Add(thongTinTKThe);
        }

        private void btnATMs_Click(object sender, EventArgs e)
        {
            uCtrATM = new ATM();
            panelEx2.Controls.Clear();
            panelEx2.Controls.Add(uCtrATM);
        }

        private void btnLSuat_Click(object sender, EventArgs e)
        {
            uCtrLaiSuat = new LaiSuatNganHang();
            panelEx2.Controls.Clear();
            panelEx2.Controls.Add(uCtrLaiSuat);

        }

        private void btnTGia_Click(object sender, EventArgs e)
        {
            uCtrTyGia = new TyGia();
            panelEx2.Controls.Clear();
            panelEx2.Controls.Add(uCtrTyGia);

        }

        private void btnDVu_Click(object sender, EventArgs e)
        {
            uCtrDVNganHang = new DichVuNganHang();
            panelEx2.Controls.Clear();
            panelEx2.Controls.Add(uCtrDVNganHang);

        }

        private void btPower_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnDKDN_Click(object sender, EventArgs e)
        {
            uCtrDKDN = new DangKyKhachHangDoanhNghiep(null);
            panelEx2.Controls.Clear();
            panelEx2.Controls.Add(uCtrDKDN);

        }

        private void btnDKCN_Click(object sender, EventArgs e)
        {
            uCtrDKCN = new DangKyKhachHangCaNhan(null);
            panelEx2.Controls.Clear();
            panelEx2.Controls.Add(uCtrDKCN);

        }

        private void btnTaiKhoanVay_Click(object sender, EventArgs e)
        {

            panelEx2.Controls.Clear();
            taiKhoanVay = new TaiKhoanVayCtrl();
            taiKhoanVay.Load(_taiKhoanDangNhap.MaTK);
            panelEx2.Controls.Add(taiKhoanVay);
        }

        private void btnTaiKhoanTietKiem_Click(object sender, EventArgs e)
        {
            panelEx2.Controls.Clear();
            taiKhoanTietKiem = new ThongTinTaiKhoanTietKiem(type);
            taiKhoanTietKiem.Init(_taiKhoanChinh.MaTK);
            panelEx2.Controls.Add(taiKhoanTietKiem);

        }

        private void btnTenCN_Click(object sender, EventArgs e)
        {
            TenChiNhanh tenChiNhanh = new TenChiNhanh();
            panelEx2.Controls.Clear();
            panelEx2.Controls.Add(tenChiNhanh);
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            panelEx2.Controls.Clear();
            thongTinCaNhan = new ThongTinCaNhan();
            thongTinCaNhan.init(taiKhoanDangNhapNV.MaDangNhap);
            panelEx2.Controls.Add(thongTinCaNhan);
        }

        private void btnDanhSachNhanVien_Click(object sender, EventArgs e)
        {
            dsNV = new DanhSachNhanVien();
            panelEx2.Controls.Clear();
            panelEx2.Controls.Add(dsNV);
            dsNV.init(1);
        }

        private void cmbType_SelectedIndexChanged(object sender, EventArgs e)
        {
            type.typeDemo = GetTypeDemo();
        }

        private void btnTKG_Click(object sender, EventArgs e)
        {
            TaoTaiKhoanMoiKH uCtr = new TaoTaiKhoanMoiKH();
            panelEx2.Controls.Clear();
            panelEx2.Controls.Add(uCtr);
        }

        private void btnDSChuyenTien_Click(object sender, EventArgs e)
        {
            panelEx2.Controls.Clear();
            ChuyenTienNgoaiNH uCtrlChuyenTien = new ChuyenTienNgoaiNH(type);
            panelEx2.Controls.Add(uCtrlChuyenTien);
        }

        private void btnThemNV_Click(object sender, EventArgs e)
        {
            themNhanVien = new Quản_lý.ThemNhanVien();
            panelEx2.Controls.Clear();
            themNhanVien.init();
            panelEx2.Controls.Add(themNhanVien);
        }

        private void btnDSChucVu_Click(object sender, EventArgs e)
        {
            panelEx2.Controls.Clear();
            dsChucVu = new Quản_lý.DanhSachChucVu(cmbType.SelectedIndex + 1);
            dsChucVu.init(cmbType.SelectedIndex + 1);
            panelEx2.Controls.Add(dsChucVu);
        }

        private void btnDSChucVuDel_Click(object sender, EventArgs e)
        {
            panelEx2.Controls.Clear();
            dsChucVuDaXoa = new Quản_lý.XemDanhSachChucVuDaXoa();
            dsChucVuDaXoa.init();
            panelEx2.Controls.Add(dsChucVuDaXoa);
        }

        private void btnThemChucVu_Click(object sender, EventArgs e)
        {
            panelEx2.Controls.Clear();
            themChucVu = new Quản_lý.InsertChucVu();
            panelEx2.Controls.Add(themChucVu);
        }

        private void btnDSKhachHang_Click(object sender, EventArgs e)
        {
            dsKH = new Nhân_viên.DanhSachKhachHang(type);
            panelEx2.Controls.Clear();
            panelEx2.Controls.Add(dsKH);
        }

    }
}
